import { Depend, Request, WxFile } from '.';
import util, { config, log, LogType } from '../util/';

/**
 * 编译静态文件
 *
 * @export
 * @class CompileStatic
 * @implements {WxFile.Core}
 */
export class CompileStatic implements WxFile.Core {
  /**
   * Creates an instance of CompileStatic.
   * @param {Request} request
   * @memberof CompileStatic
   */
  constructor(public request: Request) {
    this.request = request;
  }


  /**
  * 保存文件
  *
  * @memberof CompileStatic
  */
  save() {
    if (this.request.isJson) {
      let content = util.readFile(this.request.src)
      util.writeFile(
        this.request.dest + config.ext.js,
        `module.exports = ${content}`
      );
    } else {
      util.copyFile(this.request.src, this.request.dest);
    }
  }


  /**
  * 移除文件
  *
  * @memberof CompileStatic
  */
  remove() {
    log.msg(LogType.DELETE, this.request.destRelative)
    util.unlink(this.request.dest)
  }

  /**
  * 获取依赖列表
    *
    * @returns {Depend[]}
    * @memberof CompileStatic
    */
  getDepends(): Depend[] {
    return []
  }


  /**
   * 更新依赖列表
   *
   * @param {Request.Core[]} useRequests 可用的请求列表
   * @memberof CompileStatic
   */
  updateDepends(useRequests: Request.Core[]): void {
    //
  }
}
